#pragma once
#include <iostream>
#include <string>
std::string opers="+-*/%";//运算方法
enum{
    Divzero=1,//除0错误码
    Modzero,//模0错误码
    Unknow//未知错误
};
//计算加减乘除的类
class Task
{
    private:
    int data1_;//第一个数据
    int data2_;//第二个数据
    char operator_;//运算方法
    int result_;//运算结果
    int exitcode_;//运算退出码
    public:
    Task()
    {
        
    }
    Task(int data1,int data2,char opeator)
    :data1_(data1),data2_(data2),operator_(opeator),result_(0),exitcode_(0)
    {

    }
    void operator()()
    {
        run();
    }
    void run()//运算
    {
        switch(operator_)
        {
            case '+':
            result_=data1_+data2_;
            break;
            case '-':
            result_=data1_-data2_;
            break;
            case '*':result_=data1_*data2_;
            break;
            case '/':if(data2_){result_=data1_/data2_;}else{exitcode_=Divzero;}
            break;
            case '%':if(data2_){result_=data1_/data2_;}else{exitcode_=Modzero;}
            break;
            default:
            exitcode_=Unknow;
            break; 
        }
    
    }
    std::string getTask()
    {
        std::string str;
        str+=std::to_string(data1_);
        str+=operator_;
        str+=std::to_string(data2_);
        str+='=';
        str+='?';
        return str;
    }
    std::string getResult()
    {
        std::string str;
        str+=std::to_string(data1_);
        str+=operator_;
        str+=std::to_string(data2_);
        str+='=';
        str+=std::to_string(result_);
        str+='[';
        str+=std::to_string(exitcode_);
        str+=']';
        return str;
    }


};